<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>ws-cloud-gateway | 微观世界</title>
    <meta name="generator" content="VuePress 1.5.0">
    <link rel="icon" href="/logo.jpg">
    <link rel="manifest" href="/manifest.json">
    <meta name="description" content="计算机软件 + 物联网 + 云计算项目开发、设计、咨询">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
    <meta name="msapplication-TileColor" content="#000000">
    <link rel="preload" href="/assets/css/0.styles.55f00579.css" as="style"><link rel="preload" href="/assets/js/app.92627f89.js" as="script"><link rel="preload" href="/assets/js/2.817fcd47.js" as="script"><link rel="preload" href="/assets/js/3.62c9d964.js" as="script"><link rel="prefetch" href="/assets/js/10.791ab255.js"><link rel="prefetch" href="/assets/js/11.1dc01403.js"><link rel="prefetch" href="/assets/js/12.c421b677.js"><link rel="prefetch" href="/assets/js/13.8fa15714.js"><link rel="prefetch" href="/assets/js/14.2cca4cf4.js"><link rel="prefetch" href="/assets/js/15.e9f5696c.js"><link rel="prefetch" href="/assets/js/16.62cab094.js"><link rel="prefetch" href="/assets/js/17.6c789b79.js"><link rel="prefetch" href="/assets/js/18.74f9e612.js"><link rel="prefetch" href="/assets/js/19.98ca7c32.js"><link rel="prefetch" href="/assets/js/20.5052a859.js"><link rel="prefetch" href="/assets/js/21.3ea5972a.js"><link rel="prefetch" href="/assets/js/22.18d546b5.js"><link rel="prefetch" href="/assets/js/23.069cf840.js"><link rel="prefetch" href="/assets/js/4.58e718d2.js"><link rel="prefetch" href="/assets/js/5.addf51f6.js"><link rel="prefetch" href="/assets/js/6.a0e5b372.js"><link rel="prefetch" href="/assets/js/7.5d4ccb0f.js"><link rel="prefetch" href="/assets/js/8.ad529520.js"><link rel="prefetch" href="/assets/js/9.cc29df21.js">
    <link rel="stylesheet" href="/assets/css/0.styles.55f00579.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">微观世界</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="成功案例" class="dropdown-title"><span class="title">成功案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/product/smart-home/" class="nav-link">
  智能家居
</a></li><li class="dropdown-item"><!----> <a href="/product/share-ark/" class="nav-link">
  共享快递柜
</a></li><li class="dropdown-item"><!----> <a href="/product/share-washing/" class="nav-link">
  共享洗衣机
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源项目" class="dropdown-title"><span class="title">开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/ws-cloud/gateway/" class="nav-link router-link-exact-active router-link-active">
  ws-cloud-gateway
</a></li></ul></div></div><div class="nav-item"><a href="/contact/" class="nav-link">
  联系我们
</a></div><div class="nav-item"><a href="/about/" class="nav-link">
  关于我们
</a></div><div class="nav-item"><a href="/link/" class="nav-link">
  友情链接
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="成功案例" class="dropdown-title"><span class="title">成功案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/product/smart-home/" class="nav-link">
  智能家居
</a></li><li class="dropdown-item"><!----> <a href="/product/share-ark/" class="nav-link">
  共享快递柜
</a></li><li class="dropdown-item"><!----> <a href="/product/share-washing/" class="nav-link">
  共享洗衣机
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源项目" class="dropdown-title"><span class="title">开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/ws-cloud/gateway/" class="nav-link router-link-exact-active router-link-active">
  ws-cloud-gateway
</a></li></ul></div></div><div class="nav-item"><a href="/contact/" class="nav-link">
  联系我们
</a></div><div class="nav-item"><a href="/about/" class="nav-link">
  关于我们
</a></div><div class="nav-item"><a href="/link/" class="nav-link">
  友情链接
</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>ws-cloud-gateway</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/ws-cloud/gateway/#为什么选择-ws-cloud-gateway" class="sidebar-link">为什么选择 ws-cloud-gateway</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/ws-cloud/gateway/#文档" class="sidebar-link">文档</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/ws-cloud/gateway/#整体架构" class="sidebar-link">整体架构</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/ws-cloud/gateway/#todo" class="sidebar-link">todo</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/ws-cloud/gateway/#控制面板" class="sidebar-link">控制面板</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/ws-cloud/gateway/#更新记录" class="sidebar-link">更新记录</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="ws-cloud-gateway"><a href="#ws-cloud-gateway" class="header-anchor">#</a> ws-cloud-gateway</h1> <p>基于 openresty + etcd 实现的网关服务</p> <ul><li>gateway: <a href="https://github.com/tech-microworld/ws-cloud-gateway" target="_blank" rel="noopener noreferrer">https://github.com/tech-microworld/ws-cloud-gateway<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>dashboard: <a href="https://github.com/tech-microworld/ws-cloud-admin" target="_blank" rel="noopener noreferrer">https://github.com/tech-microworld/ws-cloud-admin<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <p>目前市面上已经有很多网关组件，ws-cloud-gateway 的定位是比更加轻量、易上手，只保留在实践中经常使用到的组件，同时可以自定义插件，满足不用业务，定制化个性功能。</p> <p>项目中参考了 <a href="https://github.com/apache/incubator-apisix" target="_blank" rel="noopener noreferrer">incubator-apisix<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>，同时有部分代码直接引用了apisix源码。</p> <h2 id="为什么选择-ws-cloud-gateway"><a href="#为什么选择-ws-cloud-gateway" class="header-anchor">#</a> 为什么选择 ws-cloud-gateway</h2> <ol><li>高性能：底层使用 nginx 异步事件驱动的网络通信模型</li> <li>轻量、灵活：将多个微服务组件整合到一起，对服务器开销小（节省服务器成本），适合初创业务，同时后期业务规模扩大后也容易调整</li> <li>上手简单学习曲线低，支持自定义插件，可灵活定制个性化功能</li> <li>上游服务节点使用etcd管理，可以通过推模式更新节点配置</li> <li>无需重启服务，可实时修改参数配置</li> <li>支持控制面板管理</li></ol> <h2 id="文档"><a href="#文档" class="header-anchor">#</a> 文档</h2> <ul><li><a href="/ws-cloud/gateway/0.x/">v0.x</a></li> <li><a href="/ws-cloud/gateway/1.x/">v1.x</a>（推荐）</li></ul> <h2 id="整体架构"><a href="#整体架构" class="header-anchor">#</a> 整体架构</h2> <p><img src="/assets/img/gateway.f38b9596.jpg" alt="整体架构"></p> <p>服务启动时，将自己的节点信息注册到etcd，包括：服务名称、ip、端口</p> <p>网关服务从etcd监听服务节点信息，保存到缓存中，从客户端请求的url中提取服务名称，通过服务名称查找节点信息，将请求转发到后端服务</p> <h2 id="todo"><a href="#todo" class="header-anchor">#</a> todo</h2> <ul><li>[x] 服务发现，动态路由</li> <li>[x] 自动生成 requestId，方便链路跟踪</li> <li>[x] 控制面板</li> <li>[x] gRPC 代理</li> <li>[ ] 动态ip防火墙</li> <li>[ ] 限流器</li> <li>[ ] 用户登录认证</li> <li>[ ] 接口协议加解密</li> <li>[ ] 统一配置管理</li></ul> <h2 id="控制面板"><a href="#控制面板" class="header-anchor">#</a> 控制面板</h2> <p><a href="http://localhost:10000/dashboard" target="_blank" rel="noopener noreferrer">http://localhost:10000/dashboard<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><img src="/assets/img/routes.46e6ca6a.jpg" alt="路由管理"></p> <p><img src="/assets/img/services.ea90d0f4.jpg" alt="服务节点管理"></p> <h2 id="更新记录"><a href="#更新记录" class="header-anchor">#</a> <a href="/ws-cloud/gateway/changelog/">更新记录</a></h2></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.92627f89.js" defer></script><script src="/assets/js/2.817fcd47.js" defer></script><script src="/assets/js/3.62c9d964.js" defer></script>
  </body>
</html>
